<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>二维数组</title>
    <script src="打印表格(函数).js" type="text/javascript"></script>
    <script type="text/javascript">
        // 定义二维数组有三种形式
        /**
         var arr = [[1,2,3],[true,false],["name","healthy"]];

         var arr = new Array(
         new Array(1,2,3),
         new Array(true,false);
         new Array("name","healthy")
         );

         var a = [1,2,3];
         var b = [true,false];
         var c = ["name","healthy"];
         var arr = [a,b,c];
         */

        var arr = [[1,2,3,4,5,6],
            ["number","string","boolean","undefined","null"],
                   ["wmf","healthy","graduate"]];

        // 访问二维数组中的元素
        // console.log(arr[2][1]);//healthy
        // 添加二维数组中的元素
        // arr[2][4] = "happy"
        // arr[3] = ["wmf","healthy","happy","boyfriend"];
        // console.log(arr);

        // 遍历二维数组
        for (var i=0;i<arr.length;i++){
            var temp = arr[i];
            for(var j=0;j<temp.length;j++){
                console.log(temp[j]);
            }
        }

        //找出以下数组的最大值以及最大值对应的索引值
        var group = [
            [59,34,123],
            [23,45,12],
            [45,56,124],
            [56,89,23],
            [78,23,97]
            ];
        var sum = 0;
        var number = 0;
        var max = group[0][0];
        var  x=0,y=0;
        for(var i=0;i<group.length;i++){
            var temp = group[i];
            for(var j=0;j<temp.length;j++){
                number++;
                sum = sum+temp[j];
                if(temp[j]>max){
                    max = temp[j];
                    x = i;
                    y = j;
                }
            }
        }
        console.log(max,x,y,number,sum);

        // 求数组的平均值（sum/num）
        var avg = sum/number;
        console.log(avg);


    </script>
</head>
<body>

</body>
</html>